package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.BasCompany;
import com.wuliu.system.service.IBasCompanyService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 客户资料Controller
 *
 * @author realue
 * @date 2023-10-24
 */
@Api(tags = {"客户管理控制器"})
@RestController
@RequestMapping("/system/company")
public class BasCompanyController extends BaseController {
    @Resource
    private IBasCompanyService basCompanyService;

    /**
     * 查询客户资料列表
     */
    @ApiOperation(value = "查询客户")
    @PreAuthorize("@ss.hasPermi('system:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasCompany basCompany) {
        basCompany.setSysAccount(getSysAccount());
        startPage();
        List<BasCompany> list = basCompanyService.selectBasCompanyList(basCompany);
        return getDataTable(list);
    }

    /**
     * 导出客户资料列表
     */
    @ApiOperation(value = "导出客户")
    @PreAuthorize("@ss.hasPermi('system:company:export')")
    @Log(title = "客户资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasCompany basCompany) {
        basCompany.setSysAccount(getSysAccount());
        List<BasCompany> list = basCompanyService.selectBasCompanyList(basCompany);
        ExcelUtil<BasCompany> util = new ExcelUtil<BasCompany>(BasCompany.class);
        util.exportExcel(response, list, "客户资料数据");
    }

    /**
     * 获取客户资料详细信息
     */
    @ApiOperation(value = "客户详情")
    @PreAuthorize("@ss.hasPermi('system:company:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(basCompanyService.selectBasCompanyById(id));
    }

    /**
     * 新增客户资料
     */
    @ApiOperation(value = "新增客户")
    @PreAuthorize("@ss.hasPermi('system:company:add')")
    @Log(title = "客户资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated BasCompany basCompany) {
        basCompany.setCreateBy(getUsername());
        basCompany.setSysAccount(getSysAccount());
        return toAjax(basCompanyService.insertBasCompany(basCompany));
    }

    /**
     * 修改客户资料
     */
    @ApiOperation(value = "编辑客户")
    @PreAuthorize("@ss.hasPermi('system:company:edit')")
    @Log(title = "客户资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated BasCompany basCompany) {
        basCompany.setUpdateBy(getUsername());
        return toAjax(basCompanyService.updateBasCompany(basCompany));
    }

    /**
     * 删除客户资料
     */
    @ApiOperation(value = "删除客户")
    @PreAuthorize("@ss.hasPermi('system:company:remove')")
    @Log(title = "客户资料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(basCompanyService.deleteBasCompanyByIds(ids));
    }
}
